package com.comtop.springboot.templet.modules.sys.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.comtop.springboot.templet.modules.sys.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 系统用户
 * 
 * @author wangjiafang
 * @version 1.0
 * @since 2016年9月18日 上午9:34:11
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUserEntity> {
	
	/**
	 * 查询用户的所有权限
	 * @param userId  用户ID
	 */
	@Select("select m.perms from sys_user_role ur LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id LEFT JOIN sys_menu m on rm.menu_id = m.menu_id where ur.user_id = #{userId}")
	List<String> queryUserAllPerms(Long userId);
	
	/**
	 * 查询用户的所有菜单ID
	 */
	@Select("select distinct rm.menu_id from sys_user_role ur  LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id where ur.user_id = #{userId}")
	List<Long> queryUserAllMenuId(Long userId);
	
	/**
	 * 根据用户名，查询系统用户
	 */
	@Select("select * from sys_user where username = #{username}")
	SysUserEntity queryByUserName(String username);
	
	/**
	 * 修改密码
	 */
	@Select("update sys_user set `password` = #{newPassword} where user_id = #{userId} and password = #{password}")
	int updatePassword(Map<String, Object> map);


	int deleteUserBatch(Object[] id);

	List<SysUserEntity> queryUserList(Map<String, Object> map);
}
